#pragma once

#include <QtGui/QFrame>
#include "MefoolImage.h"
#include "MefoolImageConverter.h"

namespace Mefool
{

/*
	Produces a QImage with the QT RGB888 format from a Mefool::Image
	(performs the necessary conversion under the hood)	

	Note: with QT's RGB888 format, if you read the QImage buffer *byte after byte* 
	then the color components appear in this order: red, green, blue.
	This format is strictly equivalent to the Mefool::ImageFormat::RGB24.
*/
class QRGB888ImageMaker
{
public:
	QRGB888ImageMaker( int width, int height );
	~QRGB888ImageMaker();
	
	bool			update( const Image& image );
	const QImage&	getQImage() const { return *mQImage; }

private:
	QImage*			mQImage;
	ImageConverter*	mImageConverter;
};

class QImageWidget: public QFrame
{ 
	Q_OBJECT

public:
	QImageWidget( QWidget* parent );
	virtual ~QImageWidget();

	void				setImage( const Mefool::Image& image );

protected:
	virtual void		paintEvent( QPaintEvent* paintEvent );

private:
	QRGB888ImageMaker*	mQImageMaker;
};

}